package com.gaga.console.core.controller.common;


import com.gaga.common.path.ApiPath;
import com.gaga.common.result.Result;
import com.gaga.console.base.controller.BaseController;
import com.gaga.console.base.utils.GPUInfoUtils;
import com.gaga.console.core.entity.dto.OpenFolderDto;
import com.gaga.console.core.service.AssistantService;
import com.gaga.metadata.common.utils.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.FileNotFoundException;
import java.io.IOException;


/**
 * 前端控制器
 *
 * @author liujia
 * @since 2022-06-01
 */
@Api(tags = "通用模块-助手")
@RestController
@RequestMapping(ApiPath.ROOT + "/common/assistant")
public class AssistantController extends BaseController {

    @Autowired
    private AssistantService assistantService;

    @ApiOperation(value = "打开弹幕助手程序")
    @GetMapping("/openBarrageAssistant")
    public Result openBarrageAssistant() throws FileNotFoundException {
        assistantService.openBarrageAssistant();
        return Result.ok();
    }

    @ApiOperation(value = "打开模型程序")
    @GetMapping("/startModel")
    public Result startModel() throws FileNotFoundException {
        assistantService.startModel();
        return Result.ok();
    }

    @ApiOperation(value = "重启模型程序")
    @GetMapping("/restartModel")
    public Result restartModel() throws FileNotFoundException {
        assistantService.restartModel();
        return Result.ok();
    }

    @ApiOperation(value = "关闭模型程序")
    @GetMapping("/shutDownModel")
    public Result shutDownModel() {
        assistantService.shutDownModel();
        return Result.ok();
    }

    @ApiOperation(value = "获取显存信息")
    @GetMapping("/getGpuInfo")
    public Result getGpuInfo() {
        return Result.ok(GPUInfoUtils.getGPUInfo());
    }

    @ApiOperation(value = "获取显存信息")
    @PostMapping("/openFolder")
    public Result openFolder(@RequestBody OpenFolderDto dto) throws IOException {
        if (dto == null || StringUtils.isBlank(dto.getPath())) {
            return Result.fail("参数错误");
        }
        assistantService.openFolder(dto.getPath());
        return Result.ok();
    }

    @ApiOperation(value = "清理音频和日志文件")
    @PostMapping("/clearLog")
    public Result clearLog() {
        assistantService.clearLog();
        return Result.ok();
    }
}
